package model

import (
	"database/sql"
)

type MrpProduction struct {
	ResCommon
	Name                string
	ProductId           int64
	Product             ProductProduct
	ProductQty          float64
	QtyProducing        float64
	ProductUomId        int64
	DatePlannedStart    sql.NullTime
	DatePlannedFinished sql.NullTime
	DateStart           sql.NullTime
	DateFinished        sql.NullTime
	UserId              sql.NullInt64
	User                ResUsers
	CompanyId           int64
	Company             ResCompany
	State               string
	MrpWorkorders       []MrpWorkorder `gorm:"foreignKey:ProductionId"`
	StockMoves          []StockMove    `gorm:"foreignKey:RawMaterialProductionId"`
	BomId               int64
	RefId               string
}

type MrpWorkorder struct {
	ResCommon
	Name                string
	ProductId           int64
	Product             ProductProduct
	ProductionId        int64
	OperationId         int64
	WorkcenterId        int64
	Workcenter          MrpWorkcenter
	DatePlannedStart    sql.NullTime //计划开始时间
	DatePlannedFinished sql.NullTime //计划结束时间
	DateStart           sql.NullTime //实际开始时间
	DateFinished        sql.NullTime //实际结束时间
	DurationExpected    float64      //预计时间
	Duration            float64      //持续时间
	DurationUnit        float64
	State               string
	QtyProduced         float64
}

type MrpWorkcenter struct {
	ResCommon
	Name      string
	CompanyId int64
}

type StockMove struct {
	ResCommon
	Name                    string
	Sequence                int
	ProductId               int64
	Product                 ProductProduct
	ProductUomQty           float64
	CompanyId               int64
	RawMaterialProductionId int64
	StockMoveLines          []StockMoveLine `gorm:"foreignKey:MoveId"`
}

type StockMoveLine struct {
	ResCommon
	MoveId  int64
	QtyDone float64
}

// MrpBom 物料清单
type MrpBom struct {
	ResCommon
	Code           string
	Active         bool
	ProductId      int64
	ProductTmplId  int64
	Product        ProductProduct
	ProductTmpl    ProductTemplate
	ProductQty     float64
	ProductUomId   int64
	Sequence       int
	CompanyId      int64
	Company        ResCompany
	Type           string
	ReadyToProduce string
	Consumption    string
	BomLines       []MrpBomLine           `gorm:"foreignKey:BomId"`
	Workcenters    []MrpRoutingWorkcenter `gorm:"foreignKey:BomId"`
	ByProducts     []MrpBomByproduct      `gorm:"foreignKey:BomId"`
}

// MrpBomLine 物料清单组件
type MrpBomLine struct {
	ResCommon
	ProductId     int64
	ProductTmplId int64
	Product       ProductProduct
	ProductTmpl   ProductTemplate
	CompanyId     int64
	ProductQty    float64
	ProductUomId  int64
	Sequence      int
	BomId         int64
}

// MrpRoutingWorkcenter 物料清单作业
type MrpRoutingWorkcenter struct {
	ResCommon
	Name            string
	Active          bool
	WorkcenterId    int64
	Workcenter      MrpWorkcenter
	Sequence        int
	BomId           int64
	TimeMode        string  //时长计算
	TimeCycleManual float64 //默认时长
	CompanyId       int64
	Company         ResCompany
}

// MrpBomByproduct 副产品
type MrpBomByproduct struct {
	ResCommon
	ProductId   int64
	Product     ProductProduct
	CompanyId   int64
	Company     ResCompany
	BomId       int64
	ProductQty  float64
	OperationId int64
	Operation   MrpRoutingWorkcenter
	Sequence    int
}
